﻿@{
    ViewBag.Title = "文档列表";
    Layout = "~/Views/Shared/_Layout_App1.cshtml";
}
    <link href="~/Areas/WeiXin/Scripts/weui.min.css" rel="stylesheet" />
    <link href="~/Areas/WeiXin/Scripts/ext.css" rel="stylesheet" />
    <link href="~/Areas/WeiXin/Scripts/jquery-weui.min.css" rel="stylesheet" />
    <!-- body 顶部加上如下代码 -->
    <div class="weui-pull-to-refresh__layer">
        <div class='weui-pull-to-refresh__arrow'></div>
        <div class='weui-pull-to-refresh__preloader'></div>
        <div class="down">下拉刷新</div>
        <div class="up">释放刷新</div>
        <div class="refresh">正在刷新</div>
    </div>
    <form id="form1" method="post">
        @Html.AntiForgeryToken()
        <div style="padding: 10px;background-color: #f2f2f2;position:relative;">
            <i class="fa fa-search" style="position:absolute;margin: 7px;font-size: 14px;color:#97989d;"></i>
            <input class="ext-input" id="searchkey" name="searchkey" value="@ViewBag.searchText" placeholder="输入文档标题可查询" style="width:calc(100% - 71px);border: 1px solid #d6d9e0;border-radius: 3px;padding-left: 24px;" />
            <input type="submit" class="ext-button" value="&nbsp;&nbsp;查询&nbsp;&nbsp;" style="width: 40px;color: #4e7199;border: none;background: none;box-shadow: none;font-size: 14px;" />
        </div>
        @{ 
            YJ.Platform.DocumentDirectory docDir = new YJ.Platform.DocumentDirectory();
            YJ.Platform.Documents bdoc = new YJ.Platform.Documents();
            Guid userID = YJ.Platform.Users.CurrentUserID;
            string dirID = Request.QueryString["dirid"];
            Dictionary<Guid, string> dicts = new Dictionary<Guid, string>();
            dicts.Add(dirID.ToGuid(), docDir.GetAllParentsName(dirID.ToGuid(), true, false));
            foreach (var dict in dicts)
            {
                long count;
                var docs = bdoc.GetList(out count, 15, 1, dict.Key.ToString(), userID.ToString(), ViewBag.searchText);
                if (docs.Rows.Count > 0)
                {

        <div class="weui-cells__title" style="font-weight:bold;"><a class="weui-cell_access" href="List?ismobile=1&dirid=@dict.Key">@dict.Value (@count)</a></div>
        <div class="weui-cells">
            @foreach (System.Data.DataRow dr in docs.Rows)
            {
                string address = WebMvc.Common.Tools.BaseUrl + "/Documents/DocRead?ismobile=1&docid=" + dr["id"].ToString();
           
            <a class="weui-cell weui-cell_access" href="@address">
                <div class="weui-cell__bd">
                  <p>@dr["Title"]</p><p class="date">发布时间:@dr["WriteTime"].ToString().ToDateTime().ToDateTimeString() 发布人:@dr["WriteUserName"].ToString()</p>
                </div>
                <div class="weui-cell__ft">
                </div>
            </a>
            }
        </div>
                }
            }
            }
        <div class="weui-loadmore" id="loaddata">
            <i class="weui-loading"></i>
            <span class="weui-loadmore__tips">正在加载</span>
        </div>
        <div class="weui-loadmore weui-loadmore_line" id="nodata" style="display:none;">
            <span class="weui-loadmore__tips">没有更多数据了</span>
        </div>
        <script src="~/Areas/WeiXin/Scripts/jquery-1.11.1.min.js"></script>
        <script src="~/Areas/WeiXin/Scripts/jquery-weui.min.js"></script>
        <script type="text/javascript">
            var pagenumber = 1;
            var loading = false;  //状态标记
            $(function ()
            {
                $(document.body).pullToRefresh();
                $(document.body).on("pull-to-refresh", function ()
                {
                    //do something
                    window.location = window.location;
                    $(document.body).pullToRefreshDone();
                });

                $("#loaddata").hide();
                $(document.body).infinite().on("infinite", function ()
                {
                    if (loading) return;
                    loading = true;
                    $("#loaddata").show();
                    $.ajax({
                        url: "GetDocs?dirid=@dirID&pagenumber=" + (++pagenumber).toString() + "&pagesize=15&SearchTitle=@ViewBag.searchText", async: false,
                    cache: false, dataType: "json", success: function (json)
                    {
                        if (json.length == 0)
                        {
                            $("#loaddata").hide();
                            $("#nodata").show();
                            $(document.body).destroyInfinite();
                            return;
                        }
                        var html = '';
                        for (var i = 0; i < json.length; i++)
                        {
                            var address = "@WebMvc.Common.Tools.BaseUrl" + "/Documents/DocRead?ismobile=1&docid=" + json[i]["id"];
                            html += '<a class="weui-cell weui-cell_access" href="' + address + '">';
                            html += '<div class="weui-cell__bd">';
                            html += '<p>' + json[i]["title"] + '<p class="date">发布时间:' + json[i]["writetime"] + ' 发布人:' + json[i]["writeuser"] + '</span></p>';
                            html += '</div>';
                            html += '<div class="weui-cell__ft">';
                            html += '</div>';
                            html += '</a>';
                        }
                        $(".weui-cells").append(html);
                        loading = false;
                        $("#loaddata").hide();
                    }
                });

                });

            });
        </script>
    </form>
